package com.example.whever;

import androidx.appcompat.app.AppCompatActivity;

import android.icu.text.Edits;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;

import com.example.whever.lacation.Location;
import com.example.whever.lacation.LocationApiCallback;
import com.example.whever.lacation.LocationApiResponse;
import com.example.whever.lacation.LocationManager;
import com.example.whever.lacation.WeatherApiCallback;
import com.example.whever.lacation.WeatherApiResponse;
import com.example.whever.lacation.WeatherListAdapter;
import com.example.whever.lacation.WeatherManager;
import com.example.whever.weather.Weather;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText input=findViewById(R.id.editTextTextPersonName);
        Button button=findViewById(R.id.button);
        ListView listView=findViewById(R.id.azzc);
        button.setOnClickListener(v -> {
            String l = input.getText().toString();
            LocationManager.queryLocation(l, locationApiResponse -> {
                for (Location datum : locationApiResponse.getData()) {
                    System.out.printf(datum.toString());
                }
                Location location = locationApiResponse.getData().get(0);
                WeatherManager.queryWeather(location.getCenter(), weatherApiResponse -> MainActivity.this.runOnUiThread(() -> {
                    WeatherListAdapter weatherListAdapter = new WeatherListAdapter(weatherApiResponse.getData(), MainActivity.this);
                    listView.setAdapter(weatherListAdapter);
                }));
            });
        });
    }
}